﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Mvc._5Dev.SettlementExpenses.ServiceReferenceSettlementExpenses;

namespace Mvc._5Dev.SettlementExpenses.Controllers
{
    public class CostCenterController : Controller
    {
        //
        // GET: /CostCenter/
        SettlementExpensesClient oSettlementExpensesClient = new SettlementExpensesClient();        
        public ActionResult Index()
        {
            return View(oSettlementExpensesClient.ListCostCenter().ToList());
        }

        //
        // GET: /CostCenter/Details/5

        public ActionResult Details(int id)
        {
            return View(oSettlementExpensesClient.GetCostCenter(id));
        }

        //
        // GET: /CostCenter/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /CostCenter/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here                
                oSettlementExpensesClient.InsertCostCenter(collection["Denomination"], collection["Description"]);                  
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /CostCenter/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(oSettlementExpensesClient.GetCostCenter(id));
        }

        //
        // POST: /CostCenter/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                oSettlementExpensesClient.UpdateCostCenter(Convert.ToInt32(collection["Id"]), collection["Denomination"], collection["Description"]);                
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /CostCenter/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(oSettlementExpensesClient.GetCostCenter(id));
        }

        //
        // POST: /CostCenter/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                oSettlementExpensesClient.DeleteCostCenter(id);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
